package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Adapter.ViewPagerAdapter;
import liumengbaio.lolzhangyoubao.Activity.Fragment.ComentFragmentForMine;
import liumengbaio.lolzhangyoubao.Activity.Fragment.MyComentFragment;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/9.
 */
public class ComentActivity extends AppCompatActivity implements View.OnClickListener {
    private TabLayout coment_tablayout;
    private ViewPager coment_viewpager;
    private List<String> tabNames;
    private List<Fragment> lists;
    private ViewPagerAdapter adapter;
    private ComentFragmentForMine coment_fragment_for_mine;
    private MyComentFragment my_coment_fragment;
    private Button head_title, coment_icon, btn_all, btn_areticle,
            head_left_title, btn_real_show, btn_play, btn_find, btn_match;
    private RadioGroup comment_radioGroup;
    private boolean flag = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.coment_activity);
        initView();
        initData();
    }

    private void initData() {
        btn_all.setOnClickListener(this);
        head_left_title.setOnClickListener(this);
        btn_real_show.setOnClickListener(this);
        btn_find.setOnClickListener(this);
        btn_match.setOnClickListener(this);
        btn_play.setOnClickListener(this);
        btn_areticle.setOnClickListener(this);
        head_title.setOnClickListener(this);
        tabNames.add("评论我的");
        tabNames.add("我的评论");
        lists.add(coment_fragment_for_mine);
        lists.add(my_coment_fragment);
        adapter = new ViewPagerAdapter(getSupportFragmentManager(), tabNames, lists);
        coment_viewpager.setAdapter(adapter);
        coment_tablayout.setupWithViewPager(coment_viewpager);
    }

    private void initView() {
        btn_all = (Button) findViewById(R.id.btn_all);
        btn_areticle = (Button) findViewById(R.id.btn_areticle);
        btn_find = (Button) findViewById(R.id.btn_find);
        btn_match = (Button) findViewById(R.id.btn_match);
        head_left_title = (Button) findViewById(R.id.head_left_title);
        btn_real_show = (Button) findViewById(R.id.btn_real_show);
        btn_play = (Button) findViewById(R.id.btn_play);
        coment_tablayout = (TabLayout) findViewById(R.id.coment_tablayout);
        coment_icon = (Button) findViewById(R.id.coment_icon);
        coment_viewpager = (ViewPager) findViewById(R.id.coment_viewpager);
        head_title = (Button) findViewById(R.id.head_title);
        comment_radioGroup = (RadioGroup) findViewById(R.id.comment_radioGroup);
        tabNames = new ArrayList<>();
        lists = new ArrayList<>();
        coment_fragment_for_mine = new ComentFragmentForMine();
        my_coment_fragment = new MyComentFragment();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.head_title:
                if (flag) {
                    comment_radioGroup.setVisibility(View.INVISIBLE);
                    coment_icon.setBackgroundResource(R.mipmap.community_arrow_down_d);
                    head_title.setTextColor(Color.WHITE);
                    btn_all.setTextColor(android.graphics.Color.parseColor("#4686e6"));
                    flag = false;

                } else {
                    comment_radioGroup.setVisibility(View.VISIBLE);
                    coment_icon.setBackgroundResource(R.mipmap.community_arrow_down_p);
                    head_title.setTextColor(android.graphics.Color.parseColor("#4686e6"));
                    flag = true;
                }
                break;
            case R.id.btn_all:
                onclick_radioButton(btn_all);
                break;
            case R.id.btn_areticle:
                onclick_radioButton(btn_areticle);
                break;
            case R.id.btn_real_show:
                onclick_radioButton(btn_real_show);
                break;
            case R.id.btn_find:
                onclick_radioButton(btn_find);
                break;
            case R.id.btn_match:
                onclick_radioButton(btn_match);
                break;
            case R.id.btn_play:
                onclick_radioButton(btn_play);
                break;
            case R.id.head_left_title:
                finish();
                break;
        }
    }

    private void onclick_radioButton(Button btn) {
        btn_all.setTextColor(Color.WHITE);
        btn_play.setTextColor(Color.WHITE);
        btn_areticle.setTextColor(Color.WHITE);
        btn_match.setTextColor(Color.WHITE);
        btn_real_show.setTextColor(Color.WHITE);
        btn_find.setTextColor(Color.WHITE);
        btn.setTextColor(android.graphics.Color.parseColor("#4686e6"));
        comment_radioGroup.setVisibility(View.INVISIBLE);
        head_title.setTextColor(Color.WHITE);
        coment_icon.setBackgroundResource(R.mipmap.community_arrow_down_d);
        flag=false;
    }
}
